/**
 * @desc 表格公共组件
 * @props  {array} dataSource 表格数据源
 * @props  {array} columns    表头数据
 * @props  {bool} loading     是否显示loading
 */
import React from 'react'
import { Table } from 'antd';
import PropTypes from 'prop-types'
import './style.less'

class TheTable extends React.Component {
    cb(e) {
        console.log(e);
    }
    guid() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0,
                v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }
    render() {
        const { dataSource, columns, loading, scroll, pagination, onChange, rowSelection } = this.props;

        columns.map(v => {
            v.ellipsis = v.ellipsis ? v.ellipsis : true
            v.align = 'center'
            v.width = v.width ? v.width : 140
            return v
        })
        return (
            <Table
                bordered
                expandable={{ defaultExpandAllRows: true }}
                loading={loading}
                pagination={pagination}
                {...this.props}
                scroll={scroll}
                dataSource={dataSource}
                columns={columns}
                rowSelection={rowSelection}
                onChange={onChange}
            />
        )
    }
}

TheTable.propTypes = {
    loading: PropTypes.bool,
    dataSource: PropTypes.array,
    columns: PropTypes.array,
    scroll: PropTypes.object,
    pagination: PropTypes.bool,
    onChange: PropTypes.func
}
TheTable.defaultProps = {
    loading: false,
    dataSource: [],
    columns: [],
    scroll: { x: 'max-content' },
    pagination: false

}
export default TheTable
